package com.ms.context;

import com.ms.constant.UserTypeConstant;

/**
 * 基于ThreadLocal封装工具类，用于保存和获取当前登录用户ID
 */
public class BaseContext {
    private static final ThreadLocal<Integer> currentId = new ThreadLocal<>();
    private static final ThreadLocal<String> currentUserType = new ThreadLocal<>();

    public static void setCurrentId(Integer id) {
        currentId.set(id);
    }

    public static Integer getCurrentId() {
        return currentId.get();
    }

    public static void setCurrentUserType(String userType) {
        currentUserType.set(userType);
    }

    public static String getCurrentUserType() {
        return currentUserType.get();
    }

    public static boolean isAdmin() {
        return UserTypeConstant.ADMIN.equals(currentUserType.get());
    }

    public static void removeCurrentId() {
        currentId.remove();
    }

    public static void removeCurrentUserType() {
        currentUserType.remove();
    }

    public static void clear() {
        removeCurrentId();
        removeCurrentUserType();
    }
}